/*     */ package com.zimbra.qa.unittest.prov.soap;
/*     */ 
/*     */ import com.google.common.collect.Maps;
/*     */ import com.zimbra.common.account.ZAttrProvisioning.CalResType;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AccountConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.SoapTransport;
/*     */ import com.zimbra.cs.account.CalendarResource;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.EntrySearchFilter.Operator;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.soap.SoapProvisioning;
/*     */ import com.zimbra.qa.QA.Bug;
/*     */ import com.zimbra.qa.unittest.TestUtil;
/*     */ import com.zimbra.qa.unittest.prov.ProvTest.SkipTestReason;
/*     */ import com.zimbra.soap.account.message.SearchCalendarResourcesRequest;
/*     */ import com.zimbra.soap.account.message.SearchCalendarResourcesResponse;
/*     */ import com.zimbra.soap.account.type.CalendarResourceInfo;
/*     */ import com.zimbra.soap.account.type.EntrySearchFilterInfo;
/*     */ import com.zimbra.soap.account.type.EntrySearchFilterMultiCond;
/*     */ import com.zimbra.soap.account.type.EntrySearchFilterSingleCond;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import org.junit.AfterClass;
/*     */ import org.junit.Assert;
/*     */ import org.junit.BeforeClass;
/*     */ import org.junit.Test;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class TestSearchCalendarResources
/*     */   extends SoapTest
/*     */ {
/*     */   private static String DOMAIN_LDAP;
/*     */   private static String DOMAIN_GSA;
/*     */   private static final String AUTHED_USER = "user1";
/*     */   private static final String KEY_FOR_SEARCH_BY_NAME = "meeting";
/*     */   private static final String ROOM_1 = "meeting-room-1";
/*     */   private static final String ROOM_2 = "meeting-room-2";
/*     */   private static final String ROOM_3 = "meeting-room-3";
/*     */   private static final String SITE_WORD_1 = "Palo";
/*     */   private static final String SITE_WORD_2 = "Alto";
/*     */   private static final String SITE = "Palo Alto";
/*     */   private static SoapProvTestUtil provUtil;
/*     */   private static Provisioning prov;
/*     */   private static Domain domain;
/*     */   
/*     */   @BeforeClass
/*     */   public static void init()
/*     */     throws Exception
/*     */   {
/*  73 */     provUtil = new SoapProvTestUtil();
/*  74 */     prov = provUtil.getProv();
/*  75 */     domain = provUtil.createDomain(baseDomainName());
/*     */     
/*  77 */     String BASE_DOMAIN_NAME = baseDomainName();
/*  78 */     DOMAIN_LDAP = "ldap." + BASE_DOMAIN_NAME;
/*  79 */     DOMAIN_GSA = "gsa." + BASE_DOMAIN_NAME;
/*     */     
/*  81 */     createDomainObjects(DOMAIN_LDAP);
/*  82 */     createDomainObjects(DOMAIN_GSA);
/*     */   }
/*     */   
/*     */   @AfterClass
/*     */   public static void cleanup() throws Exception {
/*  87 */     Cleanup.deleteAll(new String[] { baseDomainName() });
/*     */   }
/*     */   
/*     */   private static class MockCalendarResource extends CalendarResource {
/*     */     MockCalendarResource(Element e) throws ServiceException {
/*  92 */       super(e.getAttribute("id"), SoapProvisioning.getAttrs(e), null, null);
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */   private static void createCalendarResource(String localPart, Domain domain, String displayName, ZAttrProvisioning.CalResType type, int capacity, String site)
/*     */     throws Exception
/*     */   {
/* 100 */     Map<String, Object> attrs = Maps.newHashMap();
/* 101 */     attrs.put("displayName", displayName);
/* 102 */     attrs.put("zimbraCalResType", type.name());
/* 103 */     attrs.put("zimbraCalResCapacity", String.valueOf(capacity));
/* 104 */     attrs.put("zimbraCalResSite", site);
/*     */     
/* 106 */     provUtil.createCalendarResource(localPart, domain, attrs);
/*     */   }
/*     */   
/*     */   private static void createDomainObjects(String domainName) throws Exception {
/* 110 */     Domain domain = provUtil.createDomain(domainName);
/* 111 */     provUtil.createAccount("user1", domain);
/*     */     
/* 113 */     createCalendarResource("meeting-room-1", domain, "meeting-room-1", ZAttrProvisioning.CalResType.Location, 10, "Palo Alto");
/* 114 */     createCalendarResource("meeting-room-2", domain, "meeting-room-2", ZAttrProvisioning.CalResType.Location, 20, "Palo Alto");
/* 115 */     createCalendarResource("meeting-room-3", domain, "meeting-room-3", ZAttrProvisioning.CalResType.Location, 100, "Palo Alto");
/*     */   }
/*     */   
/*     */   private void searchByName(boolean ldap, String domainName) throws Exception {
/* 119 */     SoapTransport transport = authUser(TestUtil.getAddress("user1", domainName));
/*     */     
/* 121 */     Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_CALENDAR_RESOURCES_REQUEST);
/*     */     
/* 123 */     request.addAttribute("offset", 1L);
/* 124 */     request.addAttribute("limit", 2L);
/*     */     
/* 126 */     request.addElement("name").setText("meeting");
/*     */     
/* 128 */     Element response = transport.invoke(request);
/*     */     
/* 130 */     boolean paginationSupported = response.getAttributeBool("paginationSupported");
/*     */     
/*     */ 
/* 133 */     boolean found1 = false;
/* 134 */     boolean found2 = false;
/* 135 */     boolean found3 = false;
/*     */     
/* 137 */     List<CalendarResource> resources = new ArrayList();
/* 138 */     for (Element eResource : response.listElements("calresource")) {
/* 139 */       CalendarResource resource = new MockCalendarResource(eResource);
/* 140 */       resources.add(resource);
/*     */       
/* 142 */       if (resource.getName().equals(TestUtil.getAddress("meeting-room-1", domainName))) {
/* 143 */         found1 = true;
/*     */       }
/*     */       
/* 146 */       if (resource.getName().equals(TestUtil.getAddress("meeting-room-2", domainName))) {
/* 147 */         found2 = true;
/*     */       }
/*     */       
/* 150 */       if (resource.getName().equals(TestUtil.getAddress("meeting-room-3", domainName))) {
/* 151 */         found3 = true;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 156 */     if (ldap)
/*     */     {
/* 158 */       Assert.assertFalse(paginationSupported);
/*     */       
/*     */ 
/* 161 */       Assert.assertEquals(3L, resources.size());
/* 162 */       Assert.assertTrue(found1);
/* 163 */       Assert.assertTrue(found2);
/* 164 */       Assert.assertTrue(found3);
/*     */     }
/*     */     else {
/* 167 */       Assert.assertTrue(paginationSupported);
/*     */       
/*     */ 
/* 170 */       Assert.assertEquals(2L, resources.size());
/* 171 */       Assert.assertTrue(!found1);
/*     */       
/* 173 */       Assert.assertTrue(found2);
/* 174 */       Assert.assertTrue(found3);
/*     */     }
/*     */   }
/*     */   
/*     */   private void searchByFilter(boolean ldap, String domainName) throws Exception {
/* 179 */     SoapTransport transport = authUser(TestUtil.getAddress("user1", domainName));
/*     */     
/* 181 */     Element request = Element.create(transport.getRequestProtocol(), AccountConstants.SEARCH_CALENDAR_RESOURCES_REQUEST);
/*     */     
/* 183 */     request.addAttribute("offset", 1L);
/* 184 */     request.addAttribute("limit", 1L);
/*     */     
/* 186 */     Element eSearchFilter = request.addElement("searchFilter");
/* 187 */     Element eConds = eSearchFilter.addElement("conds");
/*     */     
/* 189 */     Element eCondResType = eConds.addElement("cond");
/* 190 */     eCondResType.addAttribute("attr", "zimbraCalResType");
/* 191 */     eCondResType.addAttribute("op", EntrySearchFilter.Operator.eq.name());
/* 192 */     eCondResType.addAttribute("value", "Location");
/*     */     
/* 194 */     Element eCondResCapacity = eConds.addElement("cond");
/* 195 */     eCondResCapacity.addAttribute("attr", "zimbraCalResCapacity");
/* 196 */     eCondResCapacity.addAttribute("op", EntrySearchFilter.Operator.ge.name());
/* 197 */     eCondResCapacity.addAttribute("value", "15");
/*     */     
/* 199 */     Element eCondResSite = eConds.addElement("cond");
/* 200 */     eCondResSite.addAttribute("attr", "zimbraCalResSite");
/* 201 */     eCondResSite.addAttribute("op", EntrySearchFilter.Operator.has.name());
/* 202 */     eCondResSite.addAttribute("value", "Palo");
/*     */     
/* 204 */     Element response = transport.invoke(request);
/*     */     
/* 206 */     boolean paginationSupported = response.getAttributeBool("paginationSupported");
/*     */     
/* 208 */     boolean found1 = false;
/* 209 */     boolean found2 = false;
/* 210 */     boolean found3 = false;
/*     */     
/* 212 */     List<CalendarResource> resources = new ArrayList();
/* 213 */     for (Element eResource : response.listElements("calresource")) {
/* 214 */       CalendarResource resource = new MockCalendarResource(eResource);
/* 215 */       resources.add(resource);
/*     */       
/* 217 */       if (resource.getName().equals(TestUtil.getAddress("meeting-room-1", domainName))) {
/* 218 */         found1 = true;
/*     */       }
/*     */       
/* 221 */       if (resource.getName().equals(TestUtil.getAddress("meeting-room-2", domainName))) {
/* 222 */         found2 = true;
/*     */       }
/*     */       
/* 225 */       if (resource.getName().equals(TestUtil.getAddress("meeting-room-3", domainName))) {
/* 226 */         found3 = true;
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 231 */     if (ldap)
/*     */     {
/* 233 */       Assert.assertFalse(paginationSupported);
/*     */       
/*     */ 
/* 236 */       Assert.assertEquals(2L, resources.size());
/* 237 */       Assert.assertTrue(!found1);
/* 238 */       Assert.assertTrue(found2);
/* 239 */       Assert.assertTrue(found3);
/*     */     }
/*     */     else {
/* 242 */       Assert.assertTrue(paginationSupported);
/*     */       
/*     */ 
/* 245 */       Assert.assertEquals(1L, resources.size());
/* 246 */       Assert.assertTrue(!found1);
/* 247 */       Assert.assertTrue(!found2);
/* 248 */       Assert.assertTrue(found3);
/*     */     }
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testGSASerarhByName()
/*     */     throws Exception
/*     */   {
/* 256 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/* 258 */     GalTestUtil.enableGalSyncAccount(prov, DOMAIN_GSA);
/* 259 */     searchByName(false, DOMAIN_GSA);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testGSASerarhByFilter() throws Exception {
/* 264 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/* 266 */     GalTestUtil.enableGalSyncAccount(prov, DOMAIN_GSA);
/* 267 */     searchByFilter(false, DOMAIN_GSA);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testLdapSerarhByName() throws Exception {
/* 272 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/* 274 */     searchByName(true, DOMAIN_LDAP);
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void testLdapSerarhByFilter() throws Exception {
/* 279 */     SKIP_FOR_INMEM_LDAP_SERVER(ProvTest.SkipTestReason.DN_SUBTREE_MATCH_FILTER);
/*     */     
/* 281 */     searchByFilter(true, DOMAIN_LDAP);
/*     */   }
/*     */   
/*     */   @Test
/*     */   @QA.Bug(bug={67045})
/*     */   public void reservedChar() throws Exception {
/* 287 */     Map<String, Object> attrs = Maps.newHashMap();
/* 288 */     attrs.put("displayName", "name()");
/* 289 */     attrs.put("zimbraCalResType", ZAttrProvisioning.CalResType.Location.name());
/* 290 */     attrs.put("zimbraCalResSite", "Site()");
/* 291 */     attrs.put("zimbraCalResCapacity", "10");
/* 292 */     attrs.put("zimbraCalResBuilding", "Building()");
/* 293 */     attrs.put("zimbraNotes", "Notes()");
/* 294 */     attrs.put("zimbraCalResFloor", "()");
/* 295 */     CalendarResource cr = provUtil.createCalendarResource("reservedChar", domain, attrs);
/* 296 */     String crName = cr.getName();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 318 */     SoapTransport transport = authUser("user1@phoebe.mbp");
/*     */     
/* 320 */     SearchCalendarResourcesRequest req = new SearchCalendarResourcesRequest("()");
/* 321 */     EntrySearchFilterMultiCond conds = new EntrySearchFilterMultiCond();
/*     */     
/*     */ 
/* 324 */     EntrySearchFilterSingleCond cond = new EntrySearchFilterSingleCond();
/* 325 */     cond.setAttr("zimbraCalResType");
/* 326 */     cond.setOp("eq");
/* 327 */     cond.setValue("Location");
/* 328 */     conds.addCondition(cond);
/*     */     
/* 330 */     cond = new EntrySearchFilterSingleCond();
/* 331 */     cond.setAttr("zimbraCalResSite");
/* 332 */     cond.setOp("has");
/* 333 */     cond.setValue("()");
/* 334 */     conds.addCondition(cond);
/*     */     
/* 336 */     cond = new EntrySearchFilterSingleCond();
/* 337 */     cond.setAttr("zimbraCalResCapacity");
/* 338 */     cond.setOp("ge");
/* 339 */     cond.setValue("9");
/* 340 */     conds.addCondition(cond);
/*     */     
/* 342 */     cond = new EntrySearchFilterSingleCond();
/* 343 */     cond.setAttr("zimbraCalResBuilding");
/* 344 */     cond.setOp("has");
/* 345 */     cond.setValue("()");
/* 346 */     conds.addCondition(cond);
/*     */     
/* 348 */     cond = new EntrySearchFilterSingleCond();
/* 349 */     cond.setAttr("zimbraNotes");
/* 350 */     cond.setOp("has");
/* 351 */     cond.setValue("()");
/* 352 */     conds.addCondition(cond);
/*     */     
/* 354 */     cond = new EntrySearchFilterSingleCond();
/* 355 */     cond.setAttr("zimbraCalResFloor");
/* 356 */     cond.setOp("eq");
/* 357 */     cond.setValue("()");
/* 358 */     conds.addCondition(cond);
/*     */     
/* 360 */     EntrySearchFilterInfo filter = new EntrySearchFilterInfo();
/* 361 */     filter.setCondition(conds);
/* 362 */     req.setSearchFilter(filter);
/*     */     
/* 364 */     SearchCalendarResourcesResponse resp = (SearchCalendarResourcesResponse)invokeJaxb(transport, req);
/* 365 */     List<CalendarResourceInfo> crInfo = resp.getCalendarResources();
/* 366 */     Assert.assertEquals(1L, crInfo.size());
/* 367 */     Assert.assertEquals(crName, ((CalendarResourceInfo)crInfo.get(0)).getName());
/*     */   }
/*     */   
/*     */   @Test
/*     */   public void chineseChar() throws Exception {
/* 372 */     Map<String, Object> attrs = Maps.newHashMap();
/* 373 */     attrs.put("displayName", "中文");
/* 374 */     attrs.put("zimbraCalResType", ZAttrProvisioning.CalResType.Location.name());
/* 375 */     attrs.put("zimbraCalResSite", "中文");
/* 376 */     CalendarResource cr = provUtil.createCalendarResource("chineseChar", domain, attrs);
/* 377 */     String crName = cr.getName();
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 383 */     SoapTransport transport = authUser("user1@phoebe.mbp");
/*     */     
/* 385 */     SearchCalendarResourcesRequest req = new SearchCalendarResourcesRequest("中文");
/* 386 */     EntrySearchFilterMultiCond conds = new EntrySearchFilterMultiCond();
/*     */     
/*     */ 
/* 389 */     EntrySearchFilterSingleCond cond = new EntrySearchFilterSingleCond();
/* 390 */     cond.setAttr("zimbraCalResType");
/* 391 */     cond.setOp("eq");
/* 392 */     cond.setValue("Location");
/* 393 */     conds.addCondition(cond);
/*     */     
/* 395 */     cond = new EntrySearchFilterSingleCond();
/* 396 */     cond.setAttr("zimbraCalResSite");
/* 397 */     cond.setOp("has");
/* 398 */     cond.setValue("中文");
/* 399 */     conds.addCondition(cond);
/*     */     
/* 401 */     EntrySearchFilterInfo filter = new EntrySearchFilterInfo();
/* 402 */     filter.setCondition(conds);
/* 403 */     req.setSearchFilter(filter);
/*     */     
/* 405 */     SearchCalendarResourcesResponse resp = (SearchCalendarResourcesResponse)invokeJaxb(transport, req);
/* 406 */     List<CalendarResourceInfo> crInfo = resp.getCalendarResources();
/* 407 */     Assert.assertEquals(1L, crInfo.size());
/* 408 */     Assert.assertEquals(crName, ((CalendarResourceInfo)crInfo.get(0)).getName());
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/qa/unittest/prov/soap/TestSearchCalendarResources.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */